home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / Demos / BouncingBobs.s < prev    next >
Encoding:
Text File  |  1997-07-08  |  8.3 KB  |  366 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Name:      Bouncing Bobs
  3. ;Author:    Paul Manias
  4. ;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
  5. ;
  6. ;This is a demonstration of bouncing bobs, an extension of the original
  7. ;Raining BOBs demo.  It runs in high-resolution + lace with a total of 35
  8. ;16x16 bobs at 50 FPS ('020+FAST).
  9.  
  10.     INCDIR    "INCLUDES:"
  11.     INCLUDE    "games/games_lib.i"
  12.     INCLUDE    "games/games.i"
  13.  
  14. MAX_IMAGES =    35
  15.  
  16.     SECTION    "Demo",CODE
  17.  
  18. ;===========================================================================;
  19. ;                             INITIALISE DEMO
  20. ;===========================================================================;
  21.  
  22.     STARTGMS
  23.  
  24. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  25.     move.l    GMSBase(pc),a6
  26.     CALL    AllocBlitter
  27.     tst.l    d0
  28.     bne    .Error_Blitter
  29.  
  30.     lea    PIC_BobTags(pc),a1
  31.     CALL    LoadPic
  32.     tst.l    d0
  33.     beq    .Error_Picture
  34.  
  35.     move.l    PIC_Bobs(pc),a1
  36.     move.w    PIC_Planes(a1),GSPlanes+2
  37.     move.l    PIC_Palette(a1),GSPalette
  38.  
  39.     lea    ScreenTags(pc),a0
  40.     CALL    AddScreen
  41.     tst.l    d0
  42.     beq.s    .Error_Screen
  43.  
  44.     move.l    Screen(pc),a0    ;a0 = GameScreen
  45.     moveq    #MAX_IMAGES,d1    ;d1 = Maximum amount of images.
  46.     CALL    InitRestore
  47.     tst.l    d0
  48.     beq.s    .Error_Restorelist
  49.  
  50.     move.l    Screen(pc),a0
  51.     lea    TAGS_Ball(pc),a1    ;Initialise the Ball mbob.
  52.     CALL    InitBob
  53.     tst.l    d0
  54.     beq.s    .Error_Ball
  55.  
  56.     move.l    Screen(pc),a0
  57.     lea    TAGS_Interlaced(pc),a1    ;Initialise "HiRes Interlaced" bob.
  58.     CALL    InitBob
  59.     tst.l    d0
  60.     beq.s    .Error_Laced
  61.  
  62.     move.l    Screen(pc),a0
  63.     CALL    ShowScreen
  64.  
  65.     CALL    InitJoyPorts
  66.  
  67.     bsr.s    Main
  68.  
  69. .ReturnToDOS
  70.     move.l    GMSBase(pc),a6
  71.     move.l    BOB_Interlaced(pc),a1
  72.     CALL    FreeBob
  73. .Error_Laced
  74.     move.l    MBOB_Ball(pc),a1
  75.     CALL    FreeBob
  76. .Error_Ball
  77.     move.l    Screen(pc),d0
  78.     CALL    FreeRestore
  79. .Error_Restorelist
  80.     lea    ScreenTags(pc),a0
  81.     CALL    DeleteScreen
  82. .Error_Screen
  83.     move.l    PIC_Bobs(pc),a1
  84.     CALL    FreePic
  85. .Error_Picture
  86.     CALL    FreeBlitter
  87. .Error_Blitter
  88.     MOVEM.L    (SP)+,A0-A6/D1-D7
  89.     moveq    #ERR_OK,d0
  90.     rts
  91.  
  92. ;===========================================================================;
  93. ;                                DEMO CODE
  94. ;===========================================================================;
  95.  
  96. Main:    move.l    GMSBase(pc),a6    ;a6 = GMSBase.
  97.     move.l    Screen(pc),a2    ;a2 = GameScreen.
  98.     move.l    GS_Bitmap(a2),a0    ;a0 = Bitmap.
  99.  
  100.     move.l    BOB_Interlaced(pc),a1    ;a1 = Bob to draw.
  101.     move.w    GS_ScrWidth(a2),d0
  102.     sub.w    BOB_Width(a1),d0
  103.     move.w    d0,BOB_XCoord(a1)
  104.  
  105.     move.l    GS_MemPtr2(a2),BMP_Data(a0)
  106.     CALL    DrawBob    ;>> = Draw the Bob
  107.  
  108.     move.l    GS_MemPtr1(a2),BMP_Data(a0)
  109.     CALL    DrawBob    ;>> = Draw the Bob
  110.  
  111.     moveq    #$00,d7
  112.     move.l    MBOB_Ball(pc),a1
  113.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  114.     move.w    MB_AmtEntries(a1),d2    ;a2 = Amount of entries.
  115.     subq.w    #1,d2    ;d2 = --1 for loop.
  116.     moveq    #$00,d3
  117.  
  118. .create    eor.w    #1,d3
  119.     moveq    #8,d1    ;Set Y speed here.
  120.     CALL    FastRandom
  121.     addq.w    #2,d0
  122.     move.w    d0,BE_YSpeed(a2)
  123.     move.w    #8,d1    ;Set X speed here.
  124.     CALL    FastRandom
  125.     addq.w    #1,d0
  126.     move.w    d0,BE_XSpeed(a2)
  127.     tst.w    d3
  128.     beq.s    .posx
  129.     neg.w    BE_XSpeed(a2)
  130.  
  131. .posx    move.l    Screen(pc),a0
  132.     move.w    GS_ScrHeight(a0),d1    ;Starting Y coordinate.
  133.     asr.w    #1,d1
  134.     CALL    FastRandom
  135.     asr.w    #1,d1
  136.     add.w    d1,d0
  137.     move.w    d0,BE_YCoord(a2)
  138.  
  139.     move.w    GS_ScrWidth(a0),d1    ;Starting X coordinate.
  140.     CALL    FastRandom
  141.     move.w    d0,BE_XCoord(a2)
  142.  
  143.     moveq    #12,d1
  144.     CALL    FastRandom
  145.     move.w    d0,BE_Frame(a2)
  146.     move.b    .Sets(pc,d0.w),BE_Set+1(a2)
  147.     move.w    #1,BE_FChange(a2)
  148.     move.w    d3,BE_Locked(a2)
  149.  
  150.     lea    NBE_SIZEOF(a2),a2
  151.     dbra    d2,.create
  152.     bra.s    Loop
  153.  
  154. .Sets    dc.b    0,0,0,0
  155.     dc.b    1,1,1,1
  156.     dc.b    2,2,2,2
  157.  
  158. ;---------------------------------------------------------------------------;
  159.  
  160. Loop:    addq.w    #1,d7
  161.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  162.     move.w    MB_AmtEntries(a1),d2
  163.     subq.w    #1,d2
  164. .update    bsr.s    UpdateBob
  165.     lea    NBE_SIZEOF(a2),a2
  166.     dbra    d2,.update
  167.  
  168.     move.l    Screen(pc),a0
  169.     move.l    GS_Bitmap(a0),a0
  170.     CALL    Restore
  171.  
  172.     move.l    Screen(pc),a0    ;a0 = GameScreen.
  173.     move.l    GS_Bitmap(a0),a0    ;a0 = Bitmap.
  174.     move.l    a1,a2    ;a2 = Restorelist.
  175.     move.l    MBOB_Ball(pc),a1    ;a1 = Bob to draw.
  176.     CALL    DrawBob    ;>> = Draw the Bob.
  177.  
  178.     CALL    WaitVBL    ;>> = Wait for VBL.
  179.  
  180.     move.l    Screen(pc),a0    ;a0 = GameScreen.
  181.     CALL    SwapBuffers    ;>> = Swap the buffers.
  182.  
  183.     moveq    #JPORT1,d0    ;d0 = JoyPort2
  184.     moveq    #JT_ZBXY,d1    ;d1 = Bit switch type.
  185.     CALL    ReadJoyPort    ;>> = Go get port status.
  186.     btst    #MB_LMB,d0    ;d0 = LMB pressed?
  187.     beq.s    Loop    ;>> = No.
  188.     rts
  189.  
  190. ;===========================================================================;
  191. ;                               UPDATE A BOB
  192. ;===========================================================================;
  193. ;Function: Moves the entity according to its internal settings.
  194. ;Requires: a1 = Bob structure.
  195. ;       a2 = Entry to update.
  196.  
  197. GRAVITY =    1
  198.  
  199. UpdateBob:
  200.     move.l    MB_Screen(a1),a0    ;a0 = Bitmap
  201.     move.w    BE_YCoord(a2),d0    ;d0 = YCoord
  202.     add.w    BE_YSpeed(a2),d0    ;d0 = (YCoord)+YSpeed
  203.     cmp.w    GS_ScrHeight(a0),d0    ;d0 = Should this bob bounce?
  204.     blt.s    .NoBounce    ;>> = No.
  205.     neg.w    BE_YSpeed(a2)    ;a2 = Bounce the bob!
  206.     addq.w    #GRAVITY,BE_YSpeed(a2)    ;a2 = Gravity pushes the bob down.
  207.     bra.s    .CheckX
  208. .NoBounce
  209.     move.w    d0,BE_YCoord(a2)    ;d0 = Save the change.
  210.     addq.w    #GRAVITY,BE_YSpeed(a2)    ;a2 = Gravity pushes the bob down.
  211.  
  212. .CheckX    move.w    BE_XCoord(a2),d0
  213.     add.w    BE_XSpeed(a2),d0
  214.     cmp.w    GS_ScrWidth(a0),d0
  215.     bcs.s    .NoXBounce
  216.     neg.w    BE_XSpeed(a2)
  217.     bra.s    .Animate
  218. .NoXBounce
  219.     move.w    d0,BE_XCoord(a2)
  220.  
  221. ;---------------------------------------------------------------------------;
  222.  
  223. .Animate
  224.     tst.w    BE_Locked(a2)
  225.     beq.s    .exit
  226.     move.w    d7,d6
  227.     and.w    #%00000011,d6
  228.     bne.s    .exit
  229.     move.w    BE_FChange(a2),d1
  230.     bgt.s    .Positive
  231.  
  232. .Negative
  233.     cmp.w    #1,BE_Set(a2)
  234.     bgt.s    .NBlue
  235.     beq.s    .NGreen
  236. .NRed    add.w    d1,BE_Frame(a2)
  237.     tst    BE_Frame(a2)
  238.     bge.s    .exit
  239.     move.w    #1,BE_FChange(a2)
  240.     clr.w    BE_Frame(a2)
  241.     rts
  242. .NGreen    add.w    d1,BE_Frame(a2)
  243.     cmp.w    #4,BE_Frame(a2)
  244.     bge.s    .done
  245.     move.w    #1,BE_FChange(a2)
  246.     move.w    #4,BE_Frame(a2)
  247.     rts
  248. .NBlue    add.w    d1,BE_Frame(a2)
  249.     cmp.w    #8,BE_Frame(a2)
  250.     bge.s    .done
  251.     move.w    #1,BE_FChange(a2)
  252.     move.w    #8,BE_Frame(a2)
  253. .exit    rts
  254.  
  255. .Positive
  256.     cmp.w    #1,BE_Set(a2)
  257.     bgt.s    .PBlue
  258.     beq.s    .PGreen
  259. .PRed    add.w    d1,BE_Frame(a2)
  260.     cmp.w    #3,BE_Frame(a2)
  261.     ble.s    .done
  262.     move.w    #-1,BE_FChange(a2)
  263.     move.w    #2,BE_Frame(a2)
  264.     rts
  265. .PGreen    add.w    d1,BE_Frame(a2)
  266.     cmp.w    #7,BE_Frame(a2)
  267.     ble.s    .done
  268.     move.w    #-1,BE_FChange(a2)
  269.     move.w    #6,BE_Frame(a2)
  270.     rts
  271. .PBlue    add.w    d1,BE_Frame(a2)
  272.     cmp.w    #11,BE_Frame(a2)
  273.     ble.s    .done
  274.     move.w    #-1,BE_FChange(a2)
  275.     move.w    #10,BE_Frame(a2)
  276. .done    rts
  277.  
  278. ;===========================================================================;
  279. ;                                  DATA
  280. ;===========================================================================;
  281.  
  282.   STRUCTURE    NBE,BE_SIZEOF    ;Definition for the mutated Entry-
  283.     WORD    BE_XSpeed    ;list in the Ball bob.
  284.     WORD    BE_YSpeed
  285.     WORD    BE_Set    ;0 = Red, 1 = Green, 2 = Blue.
  286.     WORD    BE_FChange
  287.     WORD    BE_Locked
  288.     LABEL    NBE_SIZEOF
  289.  
  290. ScreenTags:    dc.l  TAGS_GAMESCREEN
  291. Screen:        dc.l  0
  292.         dc.l  GSA_Rasterlist,Rasterlist
  293.         dc.l  GSA_ScrWidth,640
  294.         dc.l  GSA_ScrHeight,512
  295.         dc.l  GSA_Attrib,DBLBUFFER
  296.         dc.l  GSA_ScrMode,HIRES|LACED
  297.         dc.l  GSA_Planes
  298. GSPlanes:    dc.l  0
  299.         dc.l  GSA_Palette
  300. GSPalette:    dc.l  0
  301.         dc.l  TAGEND
  302.  
  303. Rasterlist:    COLOURLIST  300,30,00,.colours ;Line, Skip, Colnum, Colours.
  304.         RASTEND
  305. .colours    dc.l  $100000,$200000,$300000,$400000,$500000,$600000,$700000
  306.         dc.l  -1
  307.  
  308. ;---------------------------------------------------------------------------;
  309.  
  310. PIC_BobTags:    dc.l  TAGS_PICTURE
  311. PIC_Bobs:    dc.l  0
  312.         dc.l  PCA_Options,VIDEOMEM|GETPALETTE
  313.         dc.l  PCA_File,.file
  314.         dc.l  TAGEND
  315. .file        dc.b  "GMS:demos/data/PIC.HRPulse",0
  316.         even
  317.  
  318. ;---------------------------------------------------------------------------;
  319.  
  320. TAGS_Ball:    dc.l  TAGS_MBOB
  321. MBOB_Ball:    dc.l  0
  322.         dc.l  MBA_AmtEntries,MAX_IMAGES
  323.         dc.l  MBA_GfxCoords,.frames
  324.         dc.l  MBA_Width,16
  325.         dc.l  MBA_Height,16
  326.         dc.l  MBA_EntryList,Images
  327.         dc.l  MBA_Attrib,GENMASKS|CLRNOMASK|CLEAR|CLIP
  328.         dc.l  MBA_PictureTags,PIC_BobTags
  329.         dc.l  MBA_EntrySize,NBE_SIZEOF
  330.         dc.l  TAGEND
  331.  
  332. .frames        dc.w  00,16*0    ;RED
  333.         dc.w  00,16*1
  334.         dc.w  00,16*2
  335.         dc.w  00,16*3
  336.         dc.w  16,16*0    ;GREEN
  337.         dc.w  16,16*1
  338.         dc.w  16,16*2
  339.         dc.w  16,16*3
  340.         dc.w  32,16*0    ;BLUE
  341.         dc.w  32,16*1
  342.         dc.w  32,16*2
  343.         dc.w  32,16*3
  344.         dc.l  -1
  345.  
  346. ;---------------------------------------------------------------------------;
  347.  
  348. TAGS_Interlaced    dc.l  TAGS_BOB
  349. BOB_Interlaced:    dc.l  0
  350.         dc.l  BBA_GfxCoords,.frames
  351.         dc.l  BBA_Width,96
  352.         dc.l  BBA_Height,7
  353.         dc.l  BBA_Attrib,GENMASKS
  354.         dc.l  BBA_PictureTags,PIC_BobTags
  355.         dc.l  TAGEND
  356.  
  357. .frames        dc.w  0,16*4    ;X/Y Graphic
  358.         dc.l  -1
  359.  
  360. ;---------------------------------------------------------------------------;
  361.  
  362.     SECTION    Images,BSS
  363.  
  364. Images    ds.b    NBE_SIZEOF*MAX_IMAGES    ;X/Y/Frame/Speed/Set/FChange/Locked
  365.  
  366.